define(function( require ) {
    var Marionette = require('marionette');

    var tpl = require('text!components/image/1.0.0/templates/image.html');

    var utils = require('core/utils');

    return Marionette.ItemView.extend({
        template: _.template(tpl),
        tagName: 'li',
        events: {
            'click': 'select'
        },
        collectionEvents: {
            'clear': 'clear'
        },
        className: function() {
            if (this.model.collection.isSelected(this.model)) {
                return 'selected';
            } else {
                return '';
            }
        },
        select: function(e) {
            if (!this.model.collection.select(this.model)) {
                return;
            }

            this.$el.toggleClass('selected');

            if (this.model.collection.multiChoose == false) {
                this.model.collection.trigger('image:choose:success');
            }
        },
        clear: function() {
            this.$el.removeClass('selected');
        },
        templateHelpers: function() {
            return {
                utils: utils
            };
        }
    });
});